/* *****************************************************************************************

Made by www.Flashphoner.com, all rights reserved.
These sources can only be used for working with Flashphoner server.
If you want use this to create your own application (separate from Flashphoner server) � 
please contact support@flashphoner.com 

******************************************************************************************/

package com.flashphoner.api
{
	
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.flashphoner.Logger;
	import com.flashphoner.api.data.ModelLocator;
	import com.flashphoner.api.data.PhoneConfig;
	import com.flashphoner.api.management.SoundControl;
	
	import flash.events.*;
	import flash.utils.*;
	
	import mx.collections.ArrayCollection;
	
	internal class MainCommand implements ICommand
	{		
		private var hangupTimer:Timer;
		
		public function MainCommand()
		{
		}	
		
		public function execute( event : CairngormEvent ) : void
		{	
			Logger.info("PhoneCommand.execute() event.type "+event.type);
			
			var flashAPI:Flash_API = (event as MainEvent).flashAPI;
			var modelLocator:ModelLocator = flashAPI.modelLocator;
			
			
			if (event.type == MainEvent.CONNECTED){				
				if (!PhoneConfig.REGISTER_REQUIRED){				
					modelLocator.logged = true;		
				}						
			}
			if (event.type == MainEvent.REGISTERED){
				
				if (modelLocator.mode != "click2call"){
					SoundControl.getInstance().playRegisterSound();
				}
				modelLocator.logged = true;		
				flashAPI.dropRegisteredTimer();
			}	
			
			if (event.type == MainEvent.DISCONNECT){
				SoundControl.getInstance().stopRingSound();
				modelLocator.logged = false;
				modelLocator.login = null;
				modelLocator.pwd = null;
				flashAPI.calls = new ArrayCollection();
			}			
			
		}
	}
}